import 'package:flutter/material.dart';

class DetailPage extends StatelessWidget {
  const DetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('DetailPage'),
      ),
      body: Center(
        child: Column(
          children: [
            const Text('DetailPage'),
            ElevatedButton(
                onPressed: () {
                  //返回上一页 (不论方式1还是方式2都是pop返回)
                  Navigator.pop(context);
                },
                child: const Text("返回首页")),
            ElevatedButton(
                onPressed: () {
                  // 弹窗
                  // 点击弹窗(可以理解为：在路由中添加一个弹窗页面)
                  showDialog(
                      context: context,
                      builder: (context) {
                        return AlertDialog(
                          title: const Text("弹窗标题"),
                          content: const Text("弹窗内容"),
                          actions: [
                            TextButton(
                                onPressed: () {
                                  //关闭弹窗:也是Navigator.pop(context)
                                  // 点击确定按钮，关闭弹窗，从路由中移除
                                  Navigator.pop(context);
                                },
                                child: const Text("确定"))
                            // ElevatedButton(
                            //     onPressed: () {
                            //       // 关闭弹窗
                            //       Navigator.pop(context);
                            //     },
                            //     child: const Text("确定"))
                          ],
                        );
                      });
                },
                child: const Text("点击弹窗"))
          ],
        ),
      ),
    );
  }
}
